#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define LEN 1000
int main(void)
{
	char tmp[LEN+1];
	char result[LEN];
	FILE * sour,*dis;
	int size;
	int i,j;
	sour = fopen("source.js","r");
	if (sour == NULL)
	{
		printf("open file %s error \n",sour);
		exit(1);
	}
	dis = fopen("dist.js","w+");
	if (dis==NULL )
	{
		printf("Open file error %s \n",dis);
		exit(1);
	}
	size = 1000;
	i = 0;
	j = 0;
	while (size > 0)
	{
		memset(tmp,'\0',LEN+1);
		fread(tmp,LEN,1,sour);
		if (size < 0 ) 
			printf("%s\n",strerror(errno));
		printf("%s\n",tmp);
		while (i < size)
		{
			if ( i > 1 && i < size -1) 
			{
				if (tmp[i]==' ' &&tmp[i-1]>'z'&&tmp[i-1]<'A'&&tmp[i+1]>'z'&&tmp[i+1]<'A')
					i++;
				if (tmp[i]=='/'&&tmp[i+1]=='/')
					while(tmp[i] != '\n')
						i++;
				
			}
			result[j] = tmp[i];
			i++;
			j++;
			if ( j == LEN-1 )
			{
				fwrite(result,LEN,1,dis);
				memset(result,'\0',LEN);
				j = 0;
			}
		}
	}
		
	fwrite(result,j+1,1,dis);
	fclose(sour);
	fclose(dis);
		
	
	return 0;
}
